package com.yonghui.springsecurityoauth2demo.controller;

import org.springframework.security.oauth2.provider.AuthorizationRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Controller
@SessionAttributes("authorizationRequest")
public class Approvalcontroller {
    @RequestMapping("/oauth/confirm_access")
    public ModelAndView getAccessConfirmation(Map<String,Object> model, HttpServletRequest request) throws Exception{
        //从session中获取对应的请求信息
        AuthorizationRequest authorizationRequest = (AuthorizationRequest) model.get("authorizationRequest");
        ModelAndView view = new ModelAndView();
        view.setViewName("oauth-grant");
        view.addObject(  "clientId", authorizationRequest.getClientId());
        view.addObject(  "scopes", authorizationRequest.getClientId());
        view.addObject(  "responseTypes", authorizationRequest.getResponseTypes());
        view.addObject(  "redirectUri", authorizationRequest.getRedirectUri());
        view.addObject(  "state", authorizationRequest.getState());
        return view;
    }

}
